﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Linq;

public partial class Admin_QuanLyLopTC : System.Web.UI.Page
{
    DataClassesDataContext data = new DataClassesDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDanhSachLopTC();
        }
    }

    private void LoadDanhSachLopTC()
    {
        GridView_LopTC.DataSource = data.tbl_LOPTCs;
        GridView_LopTC.DataBind();
    }

    //Thêm thuộc tính cho từng dòng GridView
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.setAttribute('bgColor', this.style.backgroundColor); this.style.backgroundColor = '#FF6600';");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = this.getAttribute('bgColor');");
            tbl_LOPTC loptc = e.Row.DataItem as tbl_LOPTC;
            (e.Row.FindControl("ImageButton2") as ImageButton).CommandArgument = loptc.MsLopTC.ToString();
        }
    }
    
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView_LopTC.PageIndex = e.NewPageIndex;
        LoadDanhSachLopTC();
    }
     
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        
        if (e.CommandName == "MyDelete")
        {
            DataClassesDataContext context = new DataClassesDataContext();
            string EID = Convert.ToString(e.CommandArgument);

            context.tbl_LOPTCs.DeleteOnSubmit(context.tbl_LOPTCs.Single(p => p.MsLopTC == EID));

            context.SubmitChanges();
            LoadDanhSachLopTC();
        }
    }
}
